<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="example_5.pdf"
xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

<py:def function="pagegraphics()">
		<pageGraphics>

			<!-- biller -->
			<stroke color="#163359"/>
			<fill color="#163359"/>
			<setFont name="Helvetica" size="28"/>
			<image file="${logo}" x="10mm" y="260mm" />
			<setFont name="Helvetica-Bold" size="38"/>
			<drawString x="50mm" y="274mm">${invoice.biller.company_name}</drawString>
			<setFont name="Helvetica-Oblique" size="12"/>
			<drawString x="50mm" y="266mm">${invoice.biller.company_slogan}</drawString>
			<setFont name="Helvetica" size="9"/>
			<drawString x="10mm" y="246mm">Address:</drawString>
			<drawString x="25mm" y="246mm">${invoice.biller.street}</drawString>
			<drawString x="25mm" y="242mm">${invoice.biller.city} ${invoice.biller.state_province} ${invoice.biller.post_code}</drawString>
			<drawString x="25mm" y="238mm">${invoice.biller.country}</drawString>
			<drawString x="10mm" y="234mm">Phone:</drawString>
			<drawString x="25mm" y="234mm">${invoice.biller.phone}</drawString>
			<drawString x="10mm" y="230mm">Email:</drawString>
			<drawString x="25mm" y="230mm">${invoice.biller.user.email_address}</drawString>
			<drawString x="10mm" y="226mm">VAT Code:</drawString>
			<drawString x="25mm" y="226mm">${invoice.biller.vat_code}</drawString>

			<!-- invoice summary -->
			<stroke color="#163359"/>
			<fill color="#E9E9F2"/>
			<rect x="161mm" y="274mm" width="42mm" height="10mm"
            fill="yes" stroke="yes"/>
            <stroke color="#163359"/>
			<fill color="#163359"/>
			<setFont name="Helvetica-Bold" size="9"/>
			<drawString py:if="var == 'invoice'" x="165mm" y="280mm">Fattura N: </drawString>
			<drawString x="165mm" y="276mm">Data: </drawString>
			<drawRightString py:if="var == 'invoice'" x="200mm" y="280mm">${invoice.number}</drawRightString>
			<drawRightString x="200mm" y="276mm">${date}</drawRightString>

			<!-- bill to -->
			<setFont name="Helvetica-Bold" size="10"/>
			<drawString x="125mm" y="246mm">${invoice.customer.company_name} ${invoice.customer.company_description}</drawString>
			<setFont name="Helvetica" size="8"/>
			<drawString x="125mm" y="242mm">Address:</drawString>
			<drawString x="140mm" y="242mm">${invoice.customer.street}</drawString>
			<drawString x="140mm" y="238mm">${invoice.customer.city} ${invoice.customer.state_province} ${invoice.customer.post_code}</drawString>
			<drawString x="140mm" y="234mm">${invoice.customer.country}</drawString>
			<drawString x="125mm" y="230mm">VAT Code:</drawString>
			<drawString x="140mm" y="230mm">${invoice.customer.vat_code}</drawString>
			<drawString x="10mm" y="14mm">${invoice.biller.company_name}</drawString>
			<drawString x="105mm" y="14mm">Page <pageNumber/></drawString>
			<drawRightString x="200mm" y="14mm">VAT Code: ${invoice.biller.vat_code}</drawRightString>

		</pageGraphics>
</py:def>
<template pageSize="(210mm, 297mm)"
		  leftMargin="10mm"
		  rightMargin="10mm"
		  topMargin="10mm"
		  bottomMargin="10mm"
		  title="${invoice.biller.company_name} - ${invoice.biller.company_slogan} - ${invoice.biller.vat_code}"
		  author="${invoice.biller.company_name}"
		  allowSplitting="20">
	<pageTemplate id="first">
	    ${pagegraphics()}
		<frame id="column" x1="20mm" y1="20mm" width="170mm" height="200mm"/>
	</pageTemplate>
	<pageTemplate id="others">
	    ${pagegraphics()}
		<frame id="column" x1="20mm" y1="20mm" width="170mm" height="200mm"/>
	</pageTemplate>
</template>
<stylesheet>

	<paraStyle textColor="#163359"  name="conditions" fontName="Helvetica" fontSize="8" alignment="justify"/>
	<paraStyle textColor="#163359"  name="name" fontName="Helvetica-Bold"/>
	<paraStyle textColor="#163359"  name="payment" fontName="Helvetica" fontSize="10"/>
	<paraStyle textColor="#163359" name="headc" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER"/>
	<paraStyle textColor="#163359"  name="headr" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="RIGHT"/>
	<paraStyle textColor="#163359"  name="headl" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="LEFT"/>
	<paraStyle textColor="#163359"  name="tbodyc" fontName="Helvetica" fontSize="9.0" leading="10" alignment="CENTER"/>
	<paraStyle textColor="#163359"  name="tbodyr" fontName="Helvetica" fontSize="9.0" leading="10" alignment="RIGHT"/>
	<paraStyle textColor="#163359"  name="tbodyl" fontName="Helvetica" fontSize="9.0" leading="10" alignment="LEFT"/>
	<paraStyle textColor="#163359"  name="tbodyli" fontName="Helvetica-Oblique" fontSize="7.0" leading="10" alignment="LEFT"/>

	<blockTableStyle id="accounts">
		<blockAlignment value="RIGHT" start="-1,0" stop="-1,-1"/>
		<lineStyle kind="LINEABOVE" start="-1,-2" stop="-1,-2"/>
	</blockTableStyle>

    <blockTableStyle id="products">
      <blockAlignment value="RIGHT" start="0,0" stop="-1,-1"/>
      <blockValign value="TOP"/>
      <lineStyle kind="GRID" colorName="#163359" />
      <blockBackground colorName="#E9E9F2" start="0,0" stop="-1,0"/>
    </blockTableStyle>

    <blockTableStyle id="summary">
      <blockValign value="TOP"/>
      <lineStyle kind="GRID" colorName="#163359" start="1,0" stop="2,-1"/>
      <blockBackground colorName="#E9E9F2" start="1,0" stop="1,-1"/>
    </blockTableStyle>

    <blockTableStyle id="clients">
      <blockValign value="TOP"/>
      <lineStyle kind="GRID" colorName="#163359" start="1,0" stop="2,2"/>
      <blockBackground colorName="#e6e6e6" start="1,0" stop="1,2"/>
    </blockTableStyle>   -
</stylesheet>
<story>
	<!--  <nextFrame/>-->

	<setNextTemplate name="others"/>
				<lines>5mm 270mm 190mm 25mm</lines>
			<lines>2cm 27.3cm 19cm 27.3cm</lines>
	<spacer length="5mm" width="1mm"/>
	<blockTable colWidths="30.0,290.0,81.0,41.0,52.0,58.0" style="products">
		<tr>
			<td><para style="headc">QTY</para></td>
			<td><para style="headl">Description</para></td>
			<td><para style="headr">Unti Price</para></td>
			<td><para style="headc">VAT</para></td>
			<td><para style="headr">Total</para></td>
			<td><para style="headr">Gross</para></td>
		</tr>

    <py:for each="product in invoice.products">
	    <tr>
	        <td>
	          <para style="tbodyc">${product['qty']}</para>
	        </td>
	        <td>
	          <para style="tbodyl">${product['description']}</para>
	          <para py:if="product['description']" style="tbodyli">${product['description']}</para>
	        </td>
	        <td>
	          <para style="tbodyr">${product['unit_price']} ${invoice.currency}</para>
	        </td>
	        <td>
	          <para style="tbodyc">${product['vat']}%</para>
	        </td>
	        <td>
	          <para style="tbodyr">${product['tot_price']} ${invoice.currency}</para>
	        </td>
	        <td>
	          <para style="tbodyr">${product['gross_price']} ${invoice.currency}</para>
	        </td>
	     </tr>
    </py:for>
	</blockTable>

	<spacer length="5mm" width="1mm"/>

	<blockTable  colWidths="370,124,58.0" align="RIGHT" style="summary">

		<tr>
			<td></td><td><para style="headr">Total</para></td>
			<td><para style="tbodyr">${summary['tot']} ${invoice.currency}</para></td>
		</tr>
		<tr py:for="key, val in summary['vat'].iteritems()">
			<td></td>
			<td><para style="headr">Total (VAT ${key}%)</para></td>
			<td><para style="tbodyr">${val} ${invoice.currency}</para></td>
		</tr>
		<tr>
			<td></td>
			<td><para style="headr">Total (Gross)</para></td>
			<td><para style="tbodyr">${summary['gross']} ${invoice.currency}</para></td>
		</tr>
	</blockTable>

	<spacer length="2cm" width="1mm"/>

	<para style="payment">Payment of ${invoice.gross} ${invoice.currency} is to be made within 14 days of the invoice being sent:</para>

	<spacer length="0.5cm" width="1mm"/>

	<para style="payment">Account Name: Daniele Favara</para>

	<para style="payment">IBAN: IT26 R061 7501 4260 0000 2076 680</para>
	<para style="payment">Bank: CARIGE</para>

</story>
</document>
